package com.example.mybatis.my.shop.controller;

import com.example.mybatis.my.shop.service.TbUserService;
import com.example.mybatis.my.shop.service.impl.TbUserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(value = "/userDelete")
public class UserDeleteController extends HttpServlet {

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String id = req.getParameter("id");
        TbUserService tbUserService = new TbUserServiceImpl();
        Boolean aBoolean = tbUserService.deleteById(Long.parseLong(id));
        if (aBoolean) {
            req.setAttribute("message", "删除成功");
        } else {
            req.setAttribute("message", "删除失败");
        }
        req.getRequestDispatcher("/userList").forward(req, resp);
    }
}
